<template>
    <view>
        <!--标题和返回-->
		<cu-custom :bgColor="NavBarColor" isBack :backRouterName="backRouteName">
			<block slot="backText">返回</block>
			<block slot="content">客户表</block>
		</cu-custom>
		 <!--表单区域-->
		<view>
			<form>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">头像：</text></view>
                  <input  placeholder="请输入头像" v-model="model.profilePicture"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">客户名称：</text></view>
                  <input  placeholder="请输入客户名称" v-model="model.customerName"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">公司名称：</text></view>
                  <input  placeholder="请输入公司名称" v-model="model.companyName"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">会员等级：</text></view>
                  <input type="number" placeholder="请输入会员等级" v-model="model.membershipLevel"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">客户级别：</text></view>
                  <input type="number" placeholder="请输入客户级别" v-model="model.customerLevel"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">客户标签：</text></view>
                  <input type="number" placeholder="请输入客户标签" v-model="model.customerLabel"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">账户余额：</text></view>
                  <input type="number" placeholder="请输入账户余额" v-model="model.accountBalance"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">累计消费：</text></view>
                  <input type="number" placeholder="请输入累计消费" v-model="model.accumulatedConsumption"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">代金券：</text></view>
                  <input type="number" placeholder="请输入代金券" v-model="model.voucher"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">业务人员：</text></view>
                  <input  placeholder="请输入业务人员" v-model="model.businessPersonnel"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">客服人员：</text></view>
                  <input  placeholder="请输入客服人员" v-model="model.customerServicePersonnel"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">账户类型：</text></view>
                  <input type="number" placeholder="请输入账户类型" v-model="model.accountType"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">项目数：</text></view>
                  <input type="number" placeholder="请输入项目数" v-model="model.item"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">电子邮箱：</text></view>
                  <input  placeholder="请输入电子邮箱" v-model="model.email"/>
                </view>
              </view>
              <my-date label="最后交易：" v-model="model.finalTransaction" placeholder="请输入最后交易"></my-date>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">微信名称：</text></view>
                  <input  placeholder="请输入微信名称" v-model="model.wechatName"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">电话号码：</text></view>
                  <input  placeholder="请输入电话号码" v-model="model.phoneNumber"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">微信账号：</text></view>
                  <input  placeholder="请输入微信账号" v-model="model.wechatAccount"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">公司地址：</text></view>
                  <input  placeholder="请输入公司地址" v-model="model.companyAddress"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">备注：</text></view>
                  <input  placeholder="请输入备注" v-model="model.remark"/>
                </view>
              </view>
				<view class="padding">
					<button class="cu-btn block bg-blue margin-tb-sm lg" @click="onSubmit">
						<text v-if="loading" class="cuIcon-loading2 cuIconfont-spin"></text>提交
					</button>
				</view>
			</form>
		</view>
    </view>
</template>

<script>
    import myDate from '@/components/my-componets/my-date.vue'

    export default {
        name: "CustomerForm",
        components:{ myDate },
        props:{
          formData:{
              type:Object,
              default:()=>{},
              required:false
          }
        },
        data(){
            return {
				CustomBar: this.CustomBar,
				NavBarColor: this.NavBarColor,
				loading:false,
                model: {},
                backRouteName:'index',
                url: {
                  queryById: "/customer/customer/queryById",
                  add: "/customer/customer/add",
                  edit: "/customer/customer/edit",
                },
            }
        },
        created(){
             this.initFormData();
        },
        methods:{
           initFormData(){
               if(this.formData){
                    let dataId = this.formData.dataId;
                    this.$http.get(this.url.queryById,{params:{id:dataId}}).then((res)=>{
                        if(res.data.success){
                            console.log("表单数据",res);
                            this.model = res.data.result;
                        }
                    })
                }
            },
            onSubmit() {
                let myForm = {...this.model};
                this.loading = true;
                let url = myForm.id?this.url.edit:this.url.add;
				this.$http.post(url,myForm).then(res=>{
				   console.log("res",res)
				   this.loading = false
				   this.$Router.push({name:this.backRouteName})
				}).catch(()=>{
					this.loading = false
				});
            }
        }
    }
</script>
